﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SaleLibrary.License;
using System.Data.SqlClient;
using NHibernate;

namespace SaleLibrary
{
    public class ActiveCodeStatistics
    {
        public static ActiveCodeStatistics LoadActiveCodeStatistics(ISessionFactory sf)
        {
            ISession sess =null;
            try
            {
                string sql1 = "select count(*) from Sale_ActiveCode ";
                string sql2 = "select count(*) from Sale_ActiveCode where SendId>0 and RegId=0";
                string sql3 = "select count(*) from Sale_ActiveCode where RegId>0";
                string sql4 = "select count(*) from Sale_ActiveCode where sendId=0 and RegId=0";
                sess = sf.GetCurrentSession();

                ActiveCodeStatistics acs = new ActiveCodeStatistics();

                acs.Total = sess.CreateSQLQuery(sql1).List<int>()[0];
                acs.Sends = sess.CreateSQLQuery(sql2).List<int>()[0];
                acs.Regs = sess.CreateSQLQuery(sql3).List<int>()[0];
                acs.Availables = sess.CreateSQLQuery(sql4).List<int>()[0];
                return acs;
            }
            catch (Exception er)
            {
                throw er;
            }
            //finally
            //{
            //    if (sess.IsOpen)
            //        sess.Close();
            //}
            
        }
        
        public int Total { get; set; }

        public int Sends { get; set; }

        public int Regs { get; set; }

        public int Availables { get; set; }

    }
}
